goog.provide('dkpoints.nav.AdminRaidHandler');

goog.require('dkpoints.auth.AuthState');
goog.require('dkpoints.raid.RaidDriver');
goog.require('dkpoints.utils');


/**
 * @fileoverview
 * dkpoints.nav.AdminRaidHandler controls the entry point to the RaidDriver
 * that initiates admin-authorized access to the UI.  Other entry points
 * restrict the UI to view-only.
 */



/**
 * Handler for the path /admin/raid/(.*).
 * @param {dkpoints.ServiceProvider} sp The service provider instance.
 * @constructor
 * @implements {dkpoints.nav.Handler}
 */
dkpoints.nav.AdminRaidHandler = function(sp) {
  /**
   * @type {!Element}
   * @private
   */
  this.bodyContent_ = sp.getBodyContent();

  /**
   * @type {dkpoints.rpc.RPCService}
   * @private
   */
  this.rpc_ = sp.getRPC();

  /**
   * @type {dkpoints.status.Status}
   * @private
   */
  this.status_ = sp.getStatusManager();

  /**
   * @type {?dkpoints.raid.RaidDriver}
   * @private
   */
  this.raidDriver_ = null;
};


/**
 * Handler constructor functions need to have a requiredAuth property.
 * @type {dkpoints.auth.AuthState}
 * @const
 */
dkpoints.nav.AdminRaidHandler.requiredAuth = dkpoints.auth.AuthState.ADMIN_USER;


/**
 * The call to action for a navigation handler.
 * @param {dkpoints.nav.Path} path An object with request-specific parameters.
 */
dkpoints.nav.AdminRaidHandler.prototype.handle = function(path) {
  var driver = this.raidDriver_;
  if (! driver) {
    driver = this.raidDriver_ = new dkpoints.raid.RaidDriver(this.rpc_,
                                                             this.status_,
                                                             this.bodyContent_);
  }

  driver.createNewRaid(path);
};


/**
 * When the handler instance is already active, transition will be called on
 * new navigations instead of handle to allow the handler to more easily
 * transition set up the new state of the active driver instead of rebuilding
 * it from scratch.
 * @param {dkpoints.nav.Path} path An object with request-specific parameters.
 * @param {function()} onCancel Callback to be invoked if user decides
 *    not to navigate away from what they're doing.
 */
dkpoints.nav.AdminRaidHandler.prototype.transition = function(path, onCancel) {
};


/**
 * Save state and clear the user-interface so the next handler can use the
 * screen.
 * @param {function(boolean)} onExit Callback once exit is either
 *    complete or cancelled by the user.  Passing true to the callback means
 *    that the handler has relinquished control of thep age; false means
 *    the user opted not to navigate away.
 */
dkpoints.nav.AdminRaidHandler.prototype.exit = function(onExit) {
  var driver = this.raidDriver_;
  if (driver) {
    driver.exit(onExit);
  }
};
